import {axios} from '../utils/request'
import {ANALYSIS_PIPELINE_MODULE} from "./_prefix";
import {MOCK} from "./_prefix";

/**
 * 新建流水线 POST
 * @param {*} payload
 * @returns
 */
export const addAnalysisPipeline = async payload => {
    const {userId, pipelineName, analysisFunction, chosenColumns } = payload;
    const res = await axios.post(`${ANALYSIS_PIPELINE_MODULE}`, {
        userId,
        pipelineName,
        analysisFunction,
        chosenColumns
    })
    return res
}

/**
 * 获取所有流水线
 * @param {*} payload
 * @returns
 */
export const getAllAnalysisPipeline = payload => {
    const {userId} = payload;
    return axios.get(`${ANALYSIS_PIPELINE_MODULE}/all/${userId}`).then(res => {
    // return axios.get(`${MOCK}/analysis/pipelines/all/:userId`).then(res => {
        return res;
    });
}
/**
 * 使用水线
 * @param {*} payload
 * @returns
 */
export const useAnalysisPipeline = payload => {
    const {pipelineId, fileId} = payload;
    return axios.post(`${ANALYSIS_PIPELINE_MODULE}/${pipelineId}?fileId=${fileId}`).then(res => {
    // return axios.post(`${MOCK}/analysis/pipelines/:pipelineId`).then(res => {
        return res;
    });
}

/**
 * 删除流水线 GET
 * @param {*} payload
 * @returns
 */
export const deleteAnalysisPipeline = payload => {
    const {pipelineId} = payload;
    return axios.delete(`${ANALYSIS_PIPELINE_MODULE}/${pipelineId}`).then(res => {
    // return axios.delete(`${MOCK}/ml/pipelines/:pipelineId`).then(res => {
        return res;
    });
}